package com.ruoyi.web.controller.production.fertilizer;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.production.service.fertilizer.IFertilizerAmountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.fertilizer.FertilizerPurchase;
import com.ruoyi.production.service.fertilizer.IFertilizerPurchaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 化肥购买信息Controller
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@RestController
@RequestMapping("/production/fertilizerPurchase")
@Api(value = "化肥购买",tags = "化肥购买相关API")
public class FertilizerPurchaseController extends BaseController
{
    @Autowired
    private IFertilizerPurchaseService fertilizerPurchaseService;
    @Autowired
    private IFertilizerAmountService fertilizerAmountService;

    /**
     * 查询化肥购买信息列表
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerPurchase:list')")
    @GetMapping("/list")
    @ApiOperation("获取化肥购买表信息")
    @ApiImplicitParam(name = "fertilizerPurchase",value = "化肥购买实体类",paramType = "body", dataType = "FertilizerPurchase")
    public TableDataInfo list(FertilizerPurchase fertilizerPurchase)
    {
        startPage();
        List<FertilizerPurchase> list = fertilizerPurchaseService.selectFertilizerPurchaseList(fertilizerPurchase);
        return getDataTable(list);
    }

    /**
     * 导出化肥购买信息列表
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerPurchase:export')")
    @Log(title = "化肥购买信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出化肥购买表信息")
    @ApiImplicitParam(name = "fertilizerPurchase",value = "化肥购买实体类",paramType = "body", dataType = "FertilizerPurchase")
    public AjaxResult export(FertilizerPurchase fertilizerPurchase)
    {
        List<FertilizerPurchase> list = fertilizerPurchaseService.selectFertilizerPurchaseList(fertilizerPurchase);
        ExcelUtil<FertilizerPurchase> util = new ExcelUtil<FertilizerPurchase>(FertilizerPurchase.class);
        return util.exportExcel(list, "化肥购买信息数据");
    }

    /**
     * 获取化肥购买信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerPurchase:query')")
    @GetMapping(value = "/{fertilizerPurchaseId}")
    @ApiOperation("获取化肥购买表单个信息")
    @ApiImplicitParam(name = "fertilizerPurchaseId",value = "化肥购买实体类主键",paramType = "path", dataType = "Long")
    public AjaxResult getInfo(@PathVariable("fertilizerPurchaseId") Long fertilizerPurchaseId)
    {
        return AjaxResult.success(fertilizerPurchaseService.selectFertilizerPurchaseById(fertilizerPurchaseId));
    }

    /**
     * 新增化肥购买信息
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerPurchase:add')")
    @Log(title = "化肥购买信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增化肥购买表信息")
    @ApiImplicitParam(name = "fertilizerPurchase",value = "化肥购买实体类",paramType = "body", dataType = "FertilizerPurchase")
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody FertilizerPurchase fertilizerPurchase)
    {
        return toAjax(fertilizerPurchaseService.insertPurchaseUpdateAmount(fertilizerPurchase));
    }

    /**
     * 修改化肥购买信息
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerPurchase:edit')")
    @Log(title = "化肥购买信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改化肥购买表信息")
    @ApiImplicitParam(name = "fertilizerPurchase",value = "化肥购买实体类",paramType = "body", dataType = "FertilizerPurchase")
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody FertilizerPurchase fertilizerPurchase)
    {
        return toAjax(fertilizerPurchaseService.updateFertilizerPurchase(fertilizerPurchase));
    }

    /**
     * 删除化肥购买信息
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerPurchase:remove')")
    @Log(title = "化肥购买信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fertilizerPurchaseIds}")
    @ApiOperation("删除化肥购买信息")
    @ApiImplicitParam(name = "fertilizerPurchaseIds",value = "化肥购买实体类主键数组",paramType = "path", dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] fertilizerPurchaseIds)
    {
        return toAjax(fertilizerPurchaseService.deleteFertilizerPurchaseByIds(fertilizerPurchaseIds));
    }
}
